package com.crazyteam.datasource.annotation;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.AliasFor;

import javax.sql.DataSource;
import java.lang.annotation.*;

/**
 * @author guoyang
 * @Date 2018-01-09
 * @Desc 数据源支持注解自动装配
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
//@PropertySource(value="datasourceConf.yml", factory = YmlSourceFactory.class)
@Import(DataSourceImportBeanDefinitionRegistrar.class)
@Repeatable(MuiltDateSourceConfig.class)
public @interface DataSourceConfig {
    String ATTR_PREFIX = "prefix";
    String ATTR_VALUE = "value";
    String ATTR_MASTER = "master";
    String ATTR_ALIAS = "alias";
    String ATTR_SLAVES = "slaves";
    String ATTR_DATASOURCE_TYPE = "dataSourceType";
    String ATTR_TYPE_ALIASES_PACKAGE = "typeAliasesPackage";
    String ATTR_CONFIG_LOCATION = "configLocation";
    String ATTR_SCANNER_BASE_PACKAGES = "scannerBasePackages";
    String ATTR_MAPPER_LOCATIONS = "mapperLocations";
    String ATTR_SMART_SWITCH = "smartSwitch";
    String ATTR_IS_PRIMARY = "isPrimary";

    String prefix() default "spring.datasource.";

    /** 主库名称配置 */
    @AliasFor("master")
    String value() default "";

    /** 主库名称配置 */
    @AliasFor("value")
    String master() default "";

    /** 数据库别名 */
    String[] alias() default {};

    /** 数据库备库 */
    String[] slaves() default {};

    String typeAliasesPackage() default "";
    String configLocation() default "";
    String[] scannerBasePackages() default {};
    String[] mapperLocations() default {};

    boolean isPrimary() default false;

    boolean smartSwitch() default false;

    Class<? extends DataSource> dataSourceType() default DruidDataSource.class;

//    @AliasFor(annotation = PropertySource.class, attribute = "value")
//    String fileName() default "datasourceConf.yml";

}
